from logger import logger
from sub_events.base_event import BaseEvent

LOGGER = logger.CustomLogger()

class AssignEvent(BaseEvent):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        self.event_name_zh: str = "分配审查人"
        self.event_name_en: str = "assign"

    def pre_execute(self) -> bool:
        return self.hook.assignees in self.cfg.get("accounts", {}).get("groups")

    def execute(self) :
        comment = f"修改责任田@{self.hook.assignees.split('/')[-1]} 相关代码, 请根据修改内容联系以下人员检视后评论\"pass\"后消分:"
        user_infos = self.OCM.owner_config['userInfos']
        group_members = self.OCM.owner_config["groups"][self.hook.assignees]
        for member in group_members:
            comment += f"\n{user_infos[member]['info']}@{member.split('/')[-1]}"
        self.comment = comment
